package cn.yuxiaoyuan.controller;

import cn.yuxiaoyuan.common.util.R;
import cn.yuxiaoyuan.service.IPermissionService;
import cn.yuxiaoyuan.system.domain.Permission;
import cn.yuxiaoyuan.system.query.PermissionQuery;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author solargen
 * @version 1.0
 * @date 2025/5/19 9:51
 */
@RestController
@RequestMapping("/permission")
public class PermissionController {
    @Autowired
    private IPermissionService permissionService;
    @GetMapping("/{id}")
    public R findById(@PathVariable("id")Long id){
        return R.ok(permissionService.findById(id));
    }

    @ApiOperation(value = "查询全部用户信息")
    @GetMapping
    public R findAll(){
        return R.ok(permissionService.findAll());
    }

    @DeleteMapping("/{id}")
    public R deleteById(@PathVariable("id")Long id){
        permissionService.deleteById(id);
        return R.ok();
    }
    @PostMapping("/deleteAll")
    public R batchDelete(@RequestBody List<Long> ids){
        permissionService.batchDelete(ids);
        return R.ok();
    }

    @PostMapping
    public R add(@RequestBody Permission permission){
        if(permission.getId() == null){
            permissionService.add(permission);
        }else {
            permissionService.update(permission);
        }
        return R.ok();
    }

    @PostMapping("/list")
    public R pageList(@RequestBody PermissionQuery permissionQuery){
        return permissionService.pageList(permissionQuery);
    }
}
